﻿using System;
using System.Collections.Generic;
using System.Linq;
using Entidades;

namespace AccesoADatos
{
	public class AuxiliarExamen
	{
		#region Costructor

		EvaluacionEntities _context;
		
		public AuxiliarExamen()
		{
			_context = new EvaluacionEntities();
			_context.ContextOptions.ProxyCreationEnabled = false;
		}

		#endregion

		#region Métodos

		#region Agregar

		public Examen Agregar(Examen examen)
		{
			try
			{
				_context.Examenes.AddObject(examen);
				_context.SaveChanges();
			}
			catch (Exception ex)
			{
				throw (ex);
			}
			return examen;
		}

		#endregion

		#region Modificar

		public void Modificar(Examen examen)
		{
			try
			{
				_context.Examenes.Attach(examen);
				_context.ObjectStateManager.ChangeObjectState(examen, System.Data.EntityState.Modified);
				_context.SaveChanges();
			}
			catch (Exception ex)
			{
				throw (ex);
			}
		}

		#endregion

		#region Eliminar

		public void Eliminar(Examen examen)
		{
			try
			{
				_context.Examenes.Attach(examen);
				_context.Examenes.DeleteObject(examen);
				_context.SaveChanges();
			}
			catch (Exception ex)
			{
				throw (ex);
			}
		}

		#endregion

		#region Listar

		public List<Examen> Listar(string clave = "")
		{
			List<Examen> resultado = new List<Examen>();
			try
			{
				var q = from c in _context.Examenes
								where (clave == "" || c.Clave == clave)
								select c;

				resultado = q.ToList();
			}
			catch (Exception ex)
			{
				throw (ex);
			}
			return resultado;
		}

		#endregion 

		#endregion
	}
}
